#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2023/11/13 9:19
# @Author : 闫峰
# @File    : publish_count.py
import requests

from common.setting import ensure_path_sep
from utils.mysqlUtils.db_pool import Database


class PublisgCount:


    def publish_count(self,source_id):
        url = """http://imp-api.zhcxkj.com/api/v1/marketdata/GetShopeeV2ProductCount"""
        headers  = {
            "Authorization": "Basic aXJvYm90Ym94OmkxcjVvOEJvdGJveA=="
        }
        data = {
        "input": {
        "OrderSourceId": source_id,
        "ProductStatusType": ["NORMAL"]
        },
        "language": "zh_CN"
        }
        res = requests.post(url=url,headers=headers,json=data)
        api_num = res.json()['data']['ProductCount']
        quo_ta = res.json()['data']['Quota']
        return api_num,quo_ta

    def get_api_num(self):
        test_zhcxkj_center_promotion = Database(ensure_path_sep("\\config\\shopeev2_config.yaml.bak"), "test_jdw_database")
        get_source_id_list = """
        select
            roseaa.order_source_id
        from test_zhcxkj_center_data.rb_order_source ros
        join test_zhcxkj_center_data.rb_order_source_ebay_amazon_api roseaa
          on ros.id = roseaa.order_source_id
					 and ros.is_active = 1 -- 已激活
            and ros.is_delete = 0 -- 未删除
						and ros.order_source_type in(97)
						AND ros.order_source_country != 'CN'
						AND (roseaa.cert_idaccess_key_id !="" or roseaa.cert_idaccess_key_id is not null)
						AND ros.order_source_name not LIKE "%】%"
        """
        source_id_list = test_zhcxkj_center_promotion.fetch_all_tuple(get_source_id_list, ())
        for source_id in source_id_list:
            api_num,quo_ta = self.publish_count(source_id[0])
            print()




if __name__ == '__main__':
    PublisgCount().get_api_num()